<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item> <i class="el-icon-lx-cascades"></i> 用品审核 </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
             
                <el-input v-model="query.title" placeholder="用品名" class="handle-input mr10"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
            </div>
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
            <el-table-column type="selection" width="55" align="center" ></el-table-column>
                <el-table-column prop="id" label="编号" width="55" align="center" ></el-table-column>
                <el-table-column prop="title" label="用品名" ></el-table-column>
                
                <el-table-column prop="addres" label="地址" ></el-table-column>
                <el-table-column prop="phone" label="电话" ></el-table-column>


                <el-table-column  label="精品图片">
        <template slot-scope="scope">
            <el-popover placement="top-start" title="" trigger="hover">
              <img :src='getimg(scope.row.imgurl1)' alt="" style="width: 150px;height: 150px">
              <img slot="reference" :src=getimg(scope.row.imgurl1) style="width: 30px;height: 30px">
            </el-popover>
        </template>
      </el-table-column>
      <el-table-column  label="精品图片">
        <template slot-scope="scope">
            <el-popover placement="top-start" title="" trigger="hover">
              <img :src='getimg(scope.row.imgurl2)' alt="" style="width: 150px;height: 150px">
              <img slot="reference" :src=getimg(scope.row.imgurl2) style="width: 30px;height: 30px">
            </el-popover>
        </template>
      </el-table-column>
      <el-table-column  label="精品图片">
        <template slot-scope="scope">
            <el-popover placement="top-start" title="" trigger="hover">
              <img :src='getimg(scope.row.imgurl2)' alt="" style="width: 150px;height: 150px">
              <img slot="reference" :src=getimg(scope.row.imgurl2) style="width: 30px;height: 30px">
            </el-popover>
        </template>
      </el-table-column>


                <el-table-column prop="leixin1" label="类型1" ></el-table-column>
                <el-table-column prop="leixin2" label="类型2" ></el-table-column>
                <el-table-column prop="leixin3" label="类型3" ></el-table-column>
                <el-table-column prop="num" label="数量" ></el-table-column>

                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" icon="el-icon-edit" @click="handleEdit(scope.$index, scope.row)">操作</el-button>
                    </template>
                </el-table-column>


            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <!-- 编辑弹出框 -->
        <el-dialog title="审核" :visible.sync="editVisible" width="30%">
            <el-form ref="form" :model="form" label-width="70px">
                <el-form-item label="编号">
                    <el-input v-model="form.id" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="用品名字">
                    <el-input v-model="form.title" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="地址">
                    <el-input v-model="form.addres" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="电话">
                    <el-input v-model="form.phone" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="数量">
                    <el-input v-model="form.num" :disabled="true"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <!-- <el-button @click="editVisible = false">不通过</el-button> -->
                <el-button type="primary" @click="saveEdit1">不通过</el-button>
                <el-button type="primary" @click="saveEdit">通过</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { fetch_grade_makeup, update_grade_makeup,update_grade_makeup1} from '../../api/index';
import Axios from 'axios';
export default {
    name: 'basetable',
    data() {
        return {
            query: {
                id: '',
                title: '',
                currentPage: 0,
                pageSize: 5
            },
            value_class: '',
            value_major: '',
            tableData: [{
                id: 1,
                title: "1汉服女短袖连衣裙",
                addres: "九江学院",
                phone: "1008611",
                imgurl1: "/tupian/后台/儿童用品img/1/1.webp",
                imgurl2: "/tupian/后台/儿童用品img/1/1-1.webp",
                imgurl3: "/tupian/后台/儿童用品img/1/1-2.webp",
                leixin1: "女短袖连衣裙",
                leixin2: "女长袖连衣裙",
                leixin3: "女无袖连衣裙",
                num: 3,
            },
            {
                id: 2,
                title: "2汉服女短袖连衣裙",
                addres: "九江学院",
                phone: "1008611",
                imgurl1: "/tupian/后台/儿童用品img/1/1.webp",
                imgurl2: "/tupian/后台/儿童用品img/1/1-1.webp",
                imgurl3: "/tupian/后台/儿童用品img/1/1-2.webp",
                leixin1: "女短袖连衣裙",
                leixin2: "女长袖连衣裙",
                leixin3: "女无袖连衣裙",
                num: 3,
            },
            {
                id: 3,
                title: "3汉服女短袖连衣裙",
                addres: "九江学院",
                phone: "1008611",
                imgurl1: "/tupian/后台/儿童用品img/1/1.webp",
                imgurl2: "/tupian/后台/儿童用品img/1/1-1.webp",
                imgurl3: "/tupian/后台/儿童用品img/1/1-2.webp",
                leixin1: "女短袖连衣裙",
                leixin2: "女长袖连衣裙",
                leixin3: "女无袖连衣裙",
                num: 3,
            },
            {
                id: 4,
                title: "4汉服女短袖连衣裙",
                addres: "九江学院",
                phone: "1008611",
                imgurl1: "/tupian/后台/儿童用品img/1/1.webp",
                imgurl2: "/tupian/后台/儿童用品img/1/1-1.webp",
                imgurl3: "/tupian/后台/儿童用品img/1/1-2.webp",
                leixin1: "女短袖连衣裙",
                leixin2: "女长袖连衣裙",
                leixin3: "女无袖连衣裙",
                num: 3,
            },
            {
                id: 5,
                title: "5汉服女短袖连衣裙",
                addres: "九江学院",
                phone: "1008611",
                imgurl1: "/tupian/后台/儿童用品img/1/1.webp",
                imgurl2: "/tupian/后台/儿童用品img/1/1-1.webp",
                imgurl3: "/tupian/后台/儿童用品img/1/1-2.webp",
                leixin1: "女短袖连衣裙",
                leixin2: "女长袖连衣裙",
                leixin3: "女无袖连衣裙",
                num: 3,
            }     
        ],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            addVisible: false,
            pageTotal: 0,
            form: {},
            form_add:{},
            origin: {},
            idx: -1,
            id: -1
        };
    },
    created() {
        this.getData();
    },
    methods: {
        // 获取 easy-mock 的模拟数据
        getData() {
            fetch_grade_makeup(this.query).then(res => {
                // console.log(this.query);
                // console.log('this.res===:');
                console.log(res);
                this.tableData = res.data.data.records;
                this.pageTotal = res.data.data.total|| 5;
            });
        },

        getimg(img){
            if(img!='undefined'){
            var filename;  
            img="../../assets"+img
            // console.log(img)
            var str_url = img
            var lst_url = str_url.split('/')
            // lst_url.pop(-2)
            // str_url = '/'.join(lst_url)
            // console.log(lst_url[6])
            var a=img.indexOf("/")
            // console.log(a)
            if(img.indexOf("/")>0){//如果包含有"/"号 从最后一个"/"号+1的位置开始截取字符串
	        filename=img.substring(img.lastIndexOf("/")+1,img.length);
             }else{
	             filename=img;
             }
            // console.log(filename)
            // console.log(img)
            var imgurl
            imgurl=require('../../assets/tupian/后台/儿童用品img/'+lst_url[6]+'/'+filename)
            // console.log(imgurl)
            return imgurl
            }
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'pageIndex', 1);
            this.getData();
        },
        addStudent(){
            this.form_add={};
            this.addVisible = true;
        },
        // 多选操作
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        // 编辑操作
        handleEdit(index, row) {
            this.idx = index;
            this.form = row;
            this.origin['sid'] = row['sid'];
            this.origin['studentName'] = row['studentName'];
            this.origin['cname'] = row['cname'];
            this.origin['teacherName'] = row['teacherName'];
            this.origin['grade'] = row['grade'];
            this.editVisible = true;
        },

        saveEdit1() {
            this.editVisible = false;
            this.$message.success(`审核 ${this.idx + 1} 不通过`);

            this.$set(this.tableData, this.idx, this.form);

            this.$set(this.query, 'id', this.form.id);

            console.log(this.query);
                update_grade_makeup1(this.query).then(res=>{
                    this.getData();
                })
        },
        // 保存编辑
        saveEdit() {
            this.editVisible = false;
            this.$message.success(`审核 ${this.idx + 1} 通过`);

            this.$set(this.tableData, this.idx, this.form);

            this.$set(this.query, 'id', this.form.id);

            console.log(this.query);
            // console.log("this.row:",this.row);
            // console.log("this.origin:",this.origin);
            // let data = {};
            // data['sid'] = this.form['sid'];
            // data['cname']= this.form['cname'];
            // data['makeupGrade'] = this.form['makeupGrade']
            // data['pageIndex'] = this.query.pageIndex
            // data['pageSize'] = this.query.pageSize
            // console.log(data)
            // if (this.form['makeupGrade'] != this.origin['makeupGrade']) {
                update_grade_makeup(this.query).then(res=>{
                    // console.log();
                    this.getData();
                })
            // }
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
